package com.yanqu.road.entity.activity.huashigang;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.player.UserBaseInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author wpj
 * @Date 2020/10/4
 */
@FieldTypeAnnotation(tableName = "t_c_huashigang_user_data")
public class HuaShiGangUserData extends DataObject {
    @FieldTypeAnnotation(select = true, update = true)
    long activityId;
    @FieldTypeAnnotation(update = true)
    long serverId;
    @FieldTypeAnnotation(update = true)
    long userId;
    @FieldTypeAnnotation(desc = "当前位置")
    int x = -1;
    @FieldTypeAnnotation(desc = "当前位置")
    int y = -1;
    @FieldTypeAnnotation(desc = "是否可以选择下一关")
    boolean isFinish;
    @FieldTypeAnnotation(desc = "匹配到的怪物id")
    int monsterId;
    @FieldTypeAnnotation(desc = "玩家活动的总积分")
    long allScore;
    @FieldTypeAnnotation(desc = "意外事件随机出来的门客")
    List<Integer> randomPatronsId = new ArrayList<>();
    @FieldTypeAnnotation(desc = "宝箱事件剩余数量")
    Map<Integer, Integer> boxMap = new HashMap<>();
    @FieldTypeAnnotation(desc = "门客数据")
    Map<Integer, HuaShiGangPatrons> patronsMap = new ConcurrentHashMap<>();
    @FieldTypeAnnotation(desc = "每日重置时间")
    long resetUpdateTime;
    @FieldTypeAnnotation(desc = "积分变动事件")
    long scoreUpdateTime;
    @FieldTypeAnnotation(desc = "宝箱事件随机的箱子id")
    int boxEventId;
    @FieldTypeAnnotation(desc = "当前交通工具id")
    int transportId;
    @FieldTypeAnnotation(desc = "交通工具list")
    List<Integer> transportList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "用户基本信息")
    UserBaseInfo userBaseInfo = new UserBaseInfo();
    @FieldTypeAnnotation(desc = "开关")
    List<Integer> openSwitchList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "门客总赚钱（加上了天赋技能，用于计算boss血量）")
    long totalAbility;

    public HuaShiGangUserData() {
    }

    public HuaShiGangUserData(long activityId, long serverId, long userId) {
        this.activityId = activityId;
        this.serverId = serverId;
        this.userId = userId;
        x = -1;
        y = -1;
        isFinish = true;
        monsterId = 0;
        totalAbility = 0;
        resetUpdateTime = System.currentTimeMillis();
        scoreUpdateTime = System.currentTimeMillis();
    }

    public void reset(int x, int y) {
        setX(x);
        setY(y);
        setFinish(false);
        setMonsterId(0);
        setRandomPatronsId(new ArrayList<>());
        setBoxEventId(0);
    }
    public void initPatrons(int patronsId) {
        if (!patronsMap.containsKey(patronsId)) {
            HuaShiGangPatrons huaShiGangPatrons = new HuaShiGangPatrons(patronsId);
            patronsMap.put(patronsId, huaShiGangPatrons);
        }
    }


    public void setActivityId(long activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }

    }
    public void setServerId(long serverId) {
        if (this.serverId != serverId) {
            this.serverId = serverId;
            setOp(DataStatus.Update);
        }

    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }

    }
    public void setX(int x) {
        if (this.x != x) {
            this.x = x;
            setOp(DataStatus.Update);
        }

    }
    public void setY(int y) {
        if (this.y != y) {
            this.y = y;
            setOp(DataStatus.Update);
        }

    }
    public void setIsFinish(boolean isFinish) {
        if (this.isFinish != isFinish) {
            this.isFinish = isFinish;
            setOp(DataStatus.Update);
        }

    }
    public void setMonsterId(int monsterId) {
        if (this.monsterId != monsterId) {
            this.monsterId = monsterId;
            setOp(DataStatus.Update);
        }

    }
    public void setAllScore(long allScore) {
        if (this.allScore != allScore) {
            this.allScore = allScore;
            setOp(DataStatus.Update);
        }

    }
    public void setResetUpdateTime(long resetUpdateTime) {
        if (this.resetUpdateTime != resetUpdateTime) {
            this.resetUpdateTime = resetUpdateTime;
            setOp(DataStatus.Update);
        }

    }
    public void setScoreUpdateTime(long scoreUpdateTime) {
        if (this.scoreUpdateTime != scoreUpdateTime) {
            this.scoreUpdateTime = scoreUpdateTime;
            setOp(DataStatus.Update);
        }

    }

    public int getBoxEventId() {
        return boxEventId;
    }

    public void setBoxEventId(int boxEventId) {
        if (this.boxEventId != boxEventId) {
            this.boxEventId = boxEventId;
            setUpdateOption();
        }
    }

    public UserBaseInfo getUserBaseInfo() {
        return userBaseInfo;
    }

    public void setUserBaseInfo(UserBaseInfo userBaseInfo) {
        if (!JSON.toJSONString(this.userBaseInfo).equals(JSON.toJSONString(userBaseInfo))) {
            this.userBaseInfo = userBaseInfo;
            setUpdateOption();
        }
    }

    public long getActivityId() {
        return activityId;
    }

    public long getServerId() {
        return serverId;
    }

    public long getUserId() {
        return userId;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isFinish() {
        return isFinish;
    }

    public void setFinish(boolean finish) {
        if (this.isFinish != finish) {
            isFinish = finish;
            setUpdateOption();
        }
    }

    public int getMonsterId() {
        return monsterId;
    }

    public long getAllScore() {
        return allScore;
    }

    public List<Integer> getRandomPatronsId() {
        return randomPatronsId;
    }

    public void setRandomPatronsId(List<Integer> randomPatronsId) {
        this.randomPatronsId = randomPatronsId;
        setUpdateOption();
    }

    public Map<Integer, Integer> getBoxMap() {
        return boxMap;
    }

    public void setBoxMap(Map<Integer, Integer> boxMap) {
        this.boxMap = boxMap;
        setUpdateOption();
    }

    public Map<Integer, HuaShiGangPatrons> getPatronsMap() {
        return patronsMap;
    }

    public void setPatronsMap(Map<Integer, HuaShiGangPatrons> patronsMap) {
        this.patronsMap = patronsMap;
        setUpdateOption();
    }

    public int getTransportId() {
        return transportId;
    }

    public void setTransportId(int transportId) {
        if (this.transportId != transportId) {
            this.transportId = transportId;
            setUpdateOption();
        }
    }

    public List<Integer> getTransportList() {
        return transportList;
    }

    public void setTransportList(List<Integer> transportList) {
        this.transportList = transportList;
        setUpdateOption();
    }

    public long getResetUpdateTime() {
        return resetUpdateTime;
    }

    public long getScoreUpdateTime() {
        return scoreUpdateTime;
    }

    public List<Integer> getOpenSwitchList() {
        return openSwitchList;
    }

    public void setOpenSwitchList(List<Integer> openSwitchList) {
        if (openSwitchList == null) return;
        this.openSwitchList = openSwitchList;
        setUpdateOption();
    }

    public long getTotalAbility() {
        return totalAbility;
    }

    public void setTotalAbility(long totalAbility) {
        if (this.totalAbility != totalAbility) {
            this.totalAbility = totalAbility;
            setUpdateOption();
        }
    }
}
